package com.java.tutorials.jdk7.fileoperation;

import com.java.tutorials.Constants;

import java.io.ByteArrayOutputStream;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;

/**
 * Created by xuzhike on 2016/1/25.
 * http://www.java2s.com/Code/Java/JDK-7/CopyingFromandOutputStream.htm
 * Copying From and Output Stream
 */
public class CopyingFromandOutputStream {
    public static void main(String[] args) throws Exception {
        Path sourceFile = FileSystems.getDefault()
                .getPath(Constants.TEST_FILE_WITH_PATH);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        Files.copy(sourceFile, outputStream);
        byte arr[] = outputStream.toByteArray();
        System.out.println("The contents of " + sourceFile.getFileName());
        for (byte data : arr) {
            System.out.print((char) data);
        }

    }
}
